﻿using GDGeek;
using MrPP.Myth;
using System;
using UnityEngine;
using UnityEngine.Networking;

namespace MrPP.SerriedCabinet
{
    public class FollowerModel : NetworkBehaviour, IBridgeReceiver
    {
        [SerializeField]
        [SyncVar(hook = "poseChange")]
        private MrPP.Myth.Yggdrasil.AsgardPose _pose;

        public Action<MrPP.Myth.Yggdrasil.AsgardPose, MrPP.Myth.Yggdrasil.AsgardPose> onPoseChange;

        private void poseChange(MrPP.Myth.Yggdrasil.AsgardPose value) {

            onPoseChange?.Invoke(_pose, value);
            _pose = value;
        }

        public string handle =>this.longName();

        public void broadcast(string evt, object data)
        {
            if ("transform" == evt) {
                _pose = (MrPP.Myth.Yggdrasil.AsgardPose)(data);
            }
        }



        public void Start()
        {
            BridgeBroadcast.Instance.addReceiver(this);
        }
        public void OnDestroy()
        {
            if (BridgeBroadcast.IsInitialized)
            {

                BridgeBroadcast.Instance.removeReceiver(this);
            }
        }

    }
}